using System;
using System.ComponentModel;
using System.Data;
using System.Collections.Generic;

namespace PlacementManager
{
    
    public partial class vwUsersWDivisionWRoleComponent
    {
        
        
        
        
        /// <summary>
        /// Selects all records from the database table.
        /// </summary>
        /// <returns>A collection of objects of a type representing a row in the database table.</returns>
        [DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
        public List<vwUsersWDivisionWRole> SelectAllWRoleNameAndDivision(string roleName, int divisionId, string sortExpression)
        {
            List<vwUsersWDivisionWRole> listvwUsersWDivisionWRole = new List<vwUsersWDivisionWRole>();
            PlacementManager.DAL.vwUsersWDivisionWRole_DAL o = new PlacementManager.DAL.vwUsersWDivisionWRole_DAL();
            DataSet ds = o.SelectAllWRoleNameAndDivision(roleName, divisionId);

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                listvwUsersWDivisionWRole.Add(new vwUsersWDivisionWRole((string)row["UserName"], (int)row["UserId"], (string)row["FirstName"], (string)row["LastName"], (string)row["IdNumber"], (bool)row["IsActive"], (DateTime)row["DateCreated"], (string)row["CreatedBy"], (DateTime)row["DateUpdated"], (string)row["UpdatedBy"], (string)row["RoleName"], (int)row["DivisionId"]));
            }

            if (sortExpression == string.Empty)
            {
                sortExpression = "DateCreated desc";
            }

            listvwUsersWDivisionWRole.Sort(new vwUsersWDivisionWRoleComparer(sortExpression));
            return listvwUsersWDivisionWRole;
        
        }

        /// <summary>
        /// Selects all records from the database table.
        /// </summary>
        /// <returns>A collection of objects of a type representing a row in the database table.</returns>
        [DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
        public List<vwUsersWDivisionWRole> SimpleSearch(string roleName, int divisionId, string firstName, string lastName, string idNumber, int unitId,  string sortExpression)
        {
            List<vwUsersWDivisionWRole> listvwUsersWDivisionWRole = new List<vwUsersWDivisionWRole>();
            firstName = firstName == null ? string.Empty : firstName;
            lastName = lastName == null ? string.Empty : lastName;
            idNumber = idNumber == null ? string.Empty : idNumber;

            
            PlacementManager.DAL.vwUsersWDivisionWRole_DAL o = new PlacementManager.DAL.vwUsersWDivisionWRole_DAL();
            //DataSet ds = o.SimpleSearch(roleName, divisionId,firstName,lastName,idNumber, unitId);
            DataSet ds = o.SimpleSearch(roleName, divisionId,firstName,lastName,idNumber, unitId);
            foreach (DataRow row in ds.Tables[0].Rows)
            {
                listvwUsersWDivisionWRole.Add(new vwUsersWDivisionWRole((string)row["UserName"], (int)row["UserId"], (string)row["FirstName"], (string)row["LastName"], (string)row["IdNumber"], (bool)row["IsActive"], (DateTime)row["DateCreated"], (string)row["CreatedBy"], (DateTime)row["DateUpdated"], (string)row["UpdatedBy"], (string)row["RoleName"], (int)row["DivisionId"]));
            }

            if (sortExpression == string.Empty)
            {
                sortExpression = "LastName";
            }

            listvwUsersWDivisionWRole.Sort(new vwUsersWDivisionWRoleComparer(sortExpression));
            return listvwUsersWDivisionWRole;

        }
    }
}
